package com.weixin.generic.pack;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Generic(java泛型学习类)
 * @Description java泛型
 * @date 2022/2/16 14:51
 * @author: wx
 * @Version 1.0
 */
public class Generic {
    @Test
    public void test() {
        People<String> people = new People<>();
        people.setUsername("erick");
        people.setAge(18);
        people.setScore(85);
        people.setOrder("第一名");
        System.out.println(people.getUsername() + "\n" + people.getAge() + "岁\n" + people.getScore() + "分\n" + people.getOrder());

        People<Integer> people1 = new People<>();
        people1.setUsername("nile");
        people1.setAge(18);
        people1.setScore(85);
        people1.setOrder(12);
        Integer[] arr = new Integer[]{1, 2, 3, 4, 5, 6};
        List<Integer> peopleList = people.getPeopleList(arr);
        for (Integer i : peopleList) {
            System.out.println(i);
        }
        System.out.println(people1.getUsername() + "\n" + people1.getAge() + "岁\n" + people1.getScore() + "分\n" + people1.getOrder());

    }

    @Test
    public void test1() {
        List<Object> list = new ArrayList<>();
        People<String> people = new People<>();
        list.add(people);
        List<String> list1 = new ArrayList<>();
        list1.add("tom");
        show(list);
        show(list1);

    }

    public void show(List<?> list) {
        for (Object o : list) {
            System.out.println(o);
        }
    }

    @Test
    public void Test02(){
        //有限制条件的通配符
        List<? extends User>  list = new ArrayList<>();
        List<? super User> list1 = new ArrayList<>();
    }
}


